<?php


function install($pdio) {
    
    $tabsSql = inst_news_tables();
    
    $pdio->beginTransaction();
    
    
    try {
    
        foreach ($tabsSql as $sql) {
            $pdio->query($sql);
        }
        
        $pdio->commit();
        
    } catch (DBExeception $e){
        $pdio->rollBack();
        return false;
    }
    
    return true;
    
}


function uninstall($pdio) {
    
    $tabsSql = uninst_news_tables();
    
    $pdio->beginTransaction();
    
    try {
    
        foreach ($tabsSql as $sql) {
            $pdio->query($sql);
        }
    
        $pdio->commit();
    
    } catch (DBExeception $e){
        $pdio->rollBack();
        return false;
    }
    
    return true;
        
    
}



function inst_news_tables() {

    $create_tables = array();

    $db_pref = DB_PREF;

    $create_tables[] = <<<SQL
CREATE TABLE `{$db_pref}news_args` (
  `argid` varchar(32) NOT NULL,
  `argument` varchar(64) NOT NULL,
  `parent` varchar(32) DEFAULT NULL,
  `description` varchar(255),
  `img_url` varchar(255),
  PRIMARY KEY (`argid`),
  UNIQUE KEY `argument` (`argument`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
SQL;

    $create_tables[] = <<<SQL
CREATE TABLE `{$db_pref}news_news` (
  `newsid` varchar(32) NOT NULL,
  `argid` varchar(32) NOT NULL,
  `parent` varchar(64) DEFAULT NULL,
  `description` varchar(255),
  PRIMARY KEY (`argid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
SQL;


    return $create_tables;


}

function uninst_news_tables() {

    $drop_tables = array();

    $db_pref = DB_PREF;

    $drop_tables[] = <<<SQL
DROP TABLE IF EXISTS `{$db_pref}news_args`;
SQL;

    $drop_tables[] = <<<SQL
DROP TABLE IF EXISTS `{$db_pref}news_news`;
SQL;


    return $drop_tables;


}